<!-- 新增检测者 -->
<div class="layuimini-main">

	<div class="layui-form layuimini-form" style="width:96%;">

		<div class="layui-form-item">
			<label class="layui-form-label required"> 联系电话 </label>
			<div class="layui-input-block">
				<input type="text" name="phone" lay-verify="phone" value="" class="layui-input" />
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label required"> 性别 </label>
			<div class="layui-input-block">
				<input type="radio" name="sex" value="1" title="男" checked="" />
				<input type="radio" name="sex" value="0" title="女" />
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label required"> 姓名 </label>
			<div class="layui-input-block">
				<input type="text" name="name" lay-verify="name" value="" class="layui-input" />
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label"> 年龄 </label>
			<div class="layui-input-block">
				<input type="number" name="age" lay-verify="age" value="" class="layui-input" />
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label"> 身高/cm </label>
			<div class="layui-input-inline">
				<input type="number" name="weight" lay-verify="weight" value="" class="layui-input"/>
			</div>
			<label class="layui-form-label"> 体重/kg </label>
			<div class="layui-input-inline">
				<input type="number" name="height" lay-verify="height" value="" class="layui-input"/>
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label"> 会员号 </label>
			<div class="layui-input-block">
				<input type="text" id="code" name="custcmerCode" lay-verify="code" value="" class="layui-input layui-disabled" />
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label"> 身份证号 </label>
			<div class="layui-input-block">
				<input type="text" name="idCard" lay-verify="idCard" value="" class="layui-input" />
			</div>
		</div>

		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn"> 保存 </button>
			</div>
		</div>
	</div>
</div>

<script src="lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="lib/jq-module/paigusu.min.js" charset="utf-8"></script>
<script>
	var a = 1;
	$("#code").val("94234"+a);
	layui.use(['form', 'table', 'layarea'], function() {
		var form = layui.form,
			layer = layui.layer,
			table = layui.table,
			layarea = layui.layarea,
			$ = layui.$;


		/**
		 * 初始化表单，要加上，不然刷新部分组件可能会不加载
		 */
		form.render();

		// 当前弹出层，防止ID被覆盖
		var parentIndex = layer.index;

		//自定义验证规则
		form.verify({
			//sex:[/^正则表达式$/, '弹出消息']
			phone: [/^1[3-9]\d{9}$/, '请输入正确的联系电话'],
			name: [/^[\u4e00-\u9fa5]{2,6}$/, '请输入正确的姓名'],
			age: [/^([1-9]\d?|1[01]\d|120)$/, '请输入正确的年龄']

		});
		//监听保存事件
		form.on('submit(saveBtn)', function(data) {
			
			//获得表单数据
			var formData = data.field;
			console.log(formData);
			// //处理表单数据
			// var formData = {
			// 	'username': formData.username
			// }
			// console.log(formData);

			//通过ajax请求提交
			$.ajax({
				url: 'http://localhost:8002/sccPatient/ins',
				type: 'post',
				data: JSON.stringify(formData),
				contentType: "application/json;charset=UTF-8",
				success: function(result) {
					console.log(result);
					a++;
					console.log(a);
					//刷新页面
					// table.reloadc ('currentTableId');
					//关闭弹出层
					layer.close(parentIndex);
				},
				error: function(result) {
					console.log(result);
				}
			});
			return false;
		});
	});
</script>
